<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Puppet cron | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Puppet cron</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Puppet/">Puppet</a>
			</span>
		
	</div>

	

	
		<h2 id="cron"><a href="#cron" class="headerlink" title="cron"></a>cron</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装和管理crontab任务</p>
<h2 id="平台"><a href="#平台" class="headerlink" title="平台"></a>平台</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;支持所有有crontab的平台</p>
<h2 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">cron &#123; logrotate:</div><div class="line">    <span class="built_in">command</span> =&gt; <span class="string">"/usr/sbin/logrotate"</span>,</div><div class="line">    user =&gt; root,</div><div class="line">    hour =&gt; 2,</div><div class="line">    minute =&gt; 0</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意,所有的cron值可以用数组表示,例如</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">cron &#123; logrotate:</div><div class="line">    <span class="built_in">command</span> =&gt; <span class="string">"/usr/sbin/logrotate"</span>,</div><div class="line">    user =&gt; root,</div><div class="line">    hour =&gt; [2, 4]</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;或者使用范围,或者 */2 这样的语法,</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">cron &#123; logrotate:</div><div class="line">    <span class="built_in">command</span> =&gt; <span class="string">"/usr/sbin/logrotate"</span>,</div><div class="line">    user =&gt; root,</div><div class="line">    hour =&gt; [<span class="string">'2-4'</span>],</div><div class="line">    minute =&gt; <span class="string">'*/10'</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="参数"><a href="#参数" class="headerlink" title="参数"></a>参数</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;除了用户和command两个参数以外,其他的参数都是可选项.</p>
<h3 id="command"><a href="#command" class="headerlink" title="command"></a>command</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;crontab要执行的命令, 环境变量按照系统本地规则进行管理,推荐使用绝对路径.</p>
<h3 id="ensure"><a href="#ensure" class="headerlink" title="ensure"></a>ensure</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定该资源是否启用,可设置成true或absent</p>
<h3 id="environment"><a href="#environment" class="headerlink" title="environment"></a>environment</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 crontab环境里面指定环境变量,例如 PATH=/bin:/usr/bin:/usr/sbin.</p>
<h3 id="hour"><a href="#hour" class="headerlink" title="hour"></a>hour</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;运行crontab的小时,可设置成0-23</p>
<h3 id="minute"><a href="#minute" class="headerlink" title="minute"></a>minute</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;运行crontab的分钟,可设置成0-59</p>
<h3 id="month"><a href="#month" class="headerlink" title="month"></a>month</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;设置crontab运行的月份,1-12</p>
<h3 id="monthday"><a href="#monthday" class="headerlink" title="monthday"></a>monthday</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;一个月份中的日子,1-31</p>
<h3 id="name"><a href="#name" class="headerlink" title="name"></a>name</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该crontab的名字,这个名字用于管理员区分不同的crontab,以及puppet管理各种资源关系.</p>
<h3 id="provider"><a href="#provider" class="headerlink" title="provider"></a>provider</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定provider,可用的provider有</p>
<ul>
<li>crontab 默认的crontab程序</li>
<li>special 特殊的管理程序,只能在freebsd上面用</li>
</ul>
<h3 id="user"><a href="#user" class="headerlink" title="user"></a>user</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把该crontab加到那个用户的crontab列表,默认是运行puppet的用户</p>
<h3 id="weekday"><a href="#weekday" class="headerlink" title="weekday"></a>weekday</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;运行crontab的星期数,0-7</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Puppet/3. Puppet cron/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
